package com.suarte.webapp.action;

import com.suarte.core.Company;
import com.suarte.core.Contact;
import com.suarte.core.DocumentStatus;
import com.suarte.core.service.CompanyManager;
import com.suarte.core.service.InvoiceManager;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.appfuse.service.GenericManager;

/**
 * @date   Dec 20, 2010
 * @author Ggutierrez
 */
public class InvoiceList extends BasePage implements Serializable {

    private InvoiceManager invoiceManager;
    private CompanyManager companyManager;
    private GenericManager<Contact, Long> contactManager;
    private Long id;
    private Long quotationId;
    private String description;
    private Date date;
    private List invoices;
    private List<Company> companies;
    private Company company;
    private List<Contact> contacts;
    private Contact contact;
    private String stStatus;
    private Date fromExpiration;
    private Date toExpiration;

    public void setInvoiceManager(InvoiceManager invoiceManager) {
        this.invoiceManager = invoiceManager;
    }

    public void setCompanyManager(CompanyManager companyManager) {
        this.companyManager = companyManager;
    }

    public void setContactManager(GenericManager<Contact, Long> contactManager) {
        this.contactManager = contactManager;
    }

    public InvoiceList() {
        setSortColumn("id"); // sets the default sort column
    }

    public String execute() {
        DocumentStatus status = stStatus != null ? DocumentStatus.valueOf(stStatus) : null;
        invoices = sort(invoiceManager.findInvoices(id, quotationId, description, date, company, contact, status, fromExpiration, toExpiration));

        return "list";
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getQuotationId() {
        return quotationId;
    }

    public void setQuotationId(Long quotationId) {
        this.quotationId = quotationId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public List getInvoices() {
        return invoices;
    }

    public void setInvoices(List invoices) {
        this.invoices = invoices;
    }

    public List<Company> getCompanies() {
        companies = companyManager.findCompanies();
        return companies;
    }

    public void setCompanies(List<Company> companies) {
        this.companies = companies;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public List<Contact> getContacts() {
        //contacts = contactManager.getAll();
        return contacts;
    }

    public void setContacts(List<Contact> contacts) {
        this.contacts = contacts;
    }

    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public String getStStatus() {
        return stStatus;
    }

    public void setStStatus(String stStatus) {
        this.stStatus = stStatus;
    }

    public Date getFromExpiration() {
        return fromExpiration;
    }

    public void setFromExpiration(Date fromExpiration) {
        this.fromExpiration = fromExpiration;
    }

    public Date getToExpiration() {
        return toExpiration;
    }

    public void setToExpiration(Date toExpiration) {
        this.toExpiration = toExpiration;
    }
}
